package com.score.system.service;

import com.score.system.dao.ScoreMapper;
import com.score.system.entity.Score;
import com.score.system.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ScoreService {
    @Autowired
    private ScoreMapper scoreMapper;
    @Autowired
    private UserService userService;

    //根据姓名来查询
    public List<Score> getByname(String name){
        //先获取用户信息
        List<Score> list = null;
        User user = userService.findUserByName(name);
        if (user != null){
            list = scoreMapper.selectBySid(user.getSid());
        }
        return list;

    }

    //根据年级来查询
    public List<Score> getBygrade(String grade){
        //先获取用户信息
        List<Score> list = new ArrayList<>();

        List<User> users = userService.findUserByGrade(grade);
        if (users != null){
            for (User user: users){
                List<Score> scores = scoreMapper.selectBySid(user.getSid());
                list.addAll(scores);
            }
            return list;
        }else{
            return null;
        }

    }


    //根据分数来查询
    public List<Score> getByscore(int score){
        return scoreMapper.selectByScore(score);

    }
}
